home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
swindows.zip
/
WINDOWS.DOC
< prev
Wrap
Text File
|
1990-04-10
|
8KB
|
142 lines
Simple Windows
SWINDOWS.TPU and HWINDOWS.TPU
Screen Windows Units for Turbo Pascal
by David C. Swaim II
The SWINDOWS.TPU and HWINDOWS.TPU files are Turbo Pascal
(version 5.5) Units used for creating screen windows in application
programs. The two units differ in the way the screens are stored when
a window is opened. When a window is open the original screen under
the window must be saved so the screen can be returned to normal when
the window is closed. The routines on these units will save and
restore the screen automatically when the OpenWindow and CloseWindow
procedures are called.
SWINDOWS.TPU stores the screen data in the data segment (or stack
if you define your WindowStorage variable inside a procedure). This
has the disadvantage of reducing the amount of storage left for the
rest of your application program. The advantage in storing the screen
data this way is that you can zero the stack allocation so you can use
the EXEC procedure to execute a child process (another program). I use
this unit in several menu shell programs I have written.
There are only two procedures to learn for the SWINDOWS.TPU. The
first of these opens a window on the screen and is called OpenWindow
(what else?). The procedure is declared by:
procedure OpenWindow(X1,Y1,X2,Y2,TxtColor,BgColor: byte;
Frame: boolean;
Title: WindowTitle;
var Stuff: WindowStorage);
Where X1 and Y1 are the x,y (column,row) coordinates of the upper left
corner of the window and X2 and Y2 are the coordinates of the lower
right corner. TxtColor is the color of the frame if one is requested
and BgColor is the background color of the window. If Frame is true a
double line box frame is drawn around the window. Title is the title
of the window and is a string which will appear in the top left of the
window frame. Stuff is a variable where the original screen data is
stored. You must declare a variable of type WindowStorage to pass to
the OpenWindow routine for it to store screen data into. Once a window
is open you can write to it using the Write or Writeln procedures. Any
GotoXY procedure is relative to the current window. The OpenWindow
procedure calls the Turbo Pascal Window procedure using X1, Y1, X2 and
Y2.
The second procedure is called CloseWindow and it will close a
window that you have previously opened. The procedure is declared by:
procedure CloseWindow(X1,Y1,X2,Y2: byte;
Stuff: WindowStorage);
Where X1, Y1, X2 and Y2 are as defined in OpenWindow and Stuff is where
the screen data for this window was stored when you opened it with
OpenWindow.
There are a few simple rules you must follow when using these
window routines. As long as you open only one window at a time you
will need only one WindowStorage variable which you can reuse for each
window. If you want to overlay windows (one window opens and a second
window is open over it) you can do that by calling OpenWindow again.
You must have a second variable of type WindowStorage to put the second
window data into. When you go to close the windows they must be closed
in reverse order from the order in which they were opened (last-in,
first-out). If you close the second window and want to make the first
window active again you must be sure that you execute the Turbo Pascal
Window procedure with the x,y coordinate information of the first
window. This is because the CloseWindow procedure executes the Turbo
Pascal Window procedure with the call: Window(1,1,80,25). This makes
all GotoXY calls relative to the entire screen instead of relative to
the previous window. Example:
{ Open First Window }
OpenWindow(X1f,Y1f,X2f,Y2f,TxtColorf,BgColorf,
True,"First Window",Stuff1);
{ Open Second Window }
OpenWindow(X1s,Y1s,X2s,Y2s,TxtColors,BgColors,
True,"Second Window",Stuff2);
{ Now close second window and make first window current }
CloseWindow(X1s,Y1s,X2s,Y2s,Stuff2);
Window(X1f,Y1f,X2f,Y2f);
{ Now close first window }
CloseWindow(X1f,Y1f,X2f,Y2f,Stuff1);
X1f, Y1f, X2f and Y2f are the coordinates of the first window and
TxtColorf and BgColorf are the color attributes of the first window.
Stuff1 is the WindowStorage variable where the original screen is
stored. X1s, Y1s, X2s and Y2s are the coordinates of the second window
and TxtColors and BgColors are the color attributes of the second
window. Stuff2 is the WindowStorage variable where the screen
containing the first window is stored.
HWINDOWS.TPU (HeapWindows) contains four procedures. The same
open and close window procedures are there along with save and restore
screen procedures. Some programs give you the option of restoring the
original DOS screen on termination. This can be done in your programs
by calling SaveScreen at the start of the program and then calling
RestoreScreen at the end. Be sure you save the cursor location at the
beginning of your program so you can place the cursor back where it was
at the end of your program. The two procedures are declared:
Procedure SaveScreen(var StashPtr: Pointer);
Procedure RestoreScreen(StashPtr: Pointer);
Where StashPtr is the pointer to the location of the screen data that
is stored in the heap.
The open and close window procedures look just like the ones
described above for SWINDOWS.TPU except for one difference. The
variable Stuff is now just a pointer to the location of the screen data
in the heap. So the declarations look like this:
procedure OpenWindow(X1,Y1,X2,Y2,TxtColor,BgColor: byte;
Frame: boolean;
Title: WindowTitle;
var Stuff: Pointer);
procedure CloseWindow(X1,Y1,X2,Y2: Byte;
Stuff: Pointer);
All other parameters passed to these procedures are the same as in the
SWINDOWS.TPU.
Because the SWINDOWS.TPU saves screens in the data segment and
because it saves only the screen data under the opened window it
operates slightly faster than the HWINDOWS.TPU. This speed difference
is only noticable on the slower XT type computers and then only when it
has the old CGA color graphics. This is because the windows procedures
access the screen memory only when the raster scan is turned off to
avoid the "snow" that you get when accessing screen RAM when scanning
is taking place. The HWINDOWS.TPU procedures are a little slower
because they save the entire screen instead of just the part under the
window. Both units initialize themselves by checking to see what type
of video adapter is installed on the computer. They do "snow checking"
only on CGA adapters.